﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//
using System.Runtime.InteropServices;
/*
Copyright 2010 Mirosław M. Mączka

This file is part of Flac2Wma.

    Flac2Wma is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Foobar is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/
namespace Flac2Wma
{
    public partial class Form4 : Form
    {
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int AnimateWindow(IntPtr hwand, int dwTime, int dwFlags);
        //
        public enum AnimateWindowFlags
        {
            AW_HOR_POSITIVE = 0x00000001,
            AW_HOR_NEGATIVE = 0x00000002,
            AW_VER_POSITIVE = 0x00000004,
            AW_VER_NEGATIVE = 0x00000008,
            AW_CENTER = 0x00000010,
            AW_HIDE = 0x00010000,
            AW_ACTIVATE = 0x00020000,
            AW_SLIDE = 0x00040000,
            AW_BLEND = 0x00080000
        }
        //
        public Form4()
        {
            InitializeComponent();
            //
            Application.DoEvents();
            //
            this.MinimizeBox = false;
            this.MaximizeBox = false;
            this.ControlBox = false;
            this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.TopMost = true;
            //
            richTextBox1.ReadOnly = true;
            richTextBox1.ScrollBars = RichTextBoxScrollBars.None;
            richTextBox1.ForeColor = Color.MidnightBlue;
            richTextBox1.BackColor = Color.LightGray;
            richTextBox1.Font = new Font(new FontFamily("Verdana"), 12f, FontStyle.Regular);
            //
            Size l = new Size(60, 60);
            label1.Size = l;
            label2.Size = l;
            label3.Size = l;
            //
            Font f = new Font(new FontFamily("Verdana"), 27.75f, FontStyle.Bold);
            label1.Font = f;
            label2.Font = f;
            label3.Font = f;
            //
            this.Refresh();//???
            Application.DoEvents();
            //
        }
        //
        public void Clear()
        {
            //
            this.Text = "";
            //
            richTextBox1.Text = "";
            //
            label1.BackColor = SystemColors.Control;
            label1.ForeColor = SystemColors.ControlText;
            //
            label2.BackColor = SystemColors.Control;
            label2.ForeColor = SystemColors.ControlText;
            //
            label3.BackColor = SystemColors.Control;
            label3.ForeColor = SystemColors.ControlText;
            //
            this.Refresh();
            Application.DoEvents();
            //
        }
        //
        public void AnimShow()
        {
            AnimateWindow(this.Handle, 200, (int)(AnimateWindowFlags.AW_BLEND | AnimateWindowFlags.AW_ACTIVATE));
            Application.DoEvents();
        }
        public void AnimHide()
        {
            AnimateWindow(this.Handle, 200, (int)(AnimateWindowFlags.AW_BLEND | AnimateWindowFlags.AW_HIDE));
            Application.DoEvents();
        }
        //
        public void SetTitle(string s)
        {
            this.Text = s;
            this.Refresh();
        }
        public void SetText(string s)
        {
            richTextBox1.Text = s;
            richTextBox1.Refresh();
        }
        //
        public void Set(int idx, bool isGood)
        {
            if (isGood)
            {
                SetGood(idx);
            }
            else
            {
                SetBad(idx);
            }
        }
        //
        public void SetBad(int idx)
        {
            switch (idx)
            {
                case 0:
                    label1.BackColor = Color.Red;
                    System.Threading.Thread.Sleep(200);
                    label1.ForeColor = Color.White;
                    label1.Refresh();
                    break;
                case 1:
                    label2.BackColor = Color.Red;
                    System.Threading.Thread.Sleep(200);
                    label2.ForeColor = Color.White;
                    label2.Refresh();
                    break;
                case 2:
                    label3.BackColor = Color.Red;
                    System.Threading.Thread.Sleep(200);
                    label3.ForeColor = Color.White;
                    label3.Refresh();
                    break;
            }
        }
        public void SetGood(int idx)
        {
            switch (idx)
            {
                case 0:
                    label1.BackColor = Color.Green;
                    System.Threading.Thread.Sleep(200);
                    label1.ForeColor = Color.White;
                    label1.Refresh();
                    break;
                case 1:
                    label2.BackColor = Color.Green;
                    System.Threading.Thread.Sleep(200);
                    label2.ForeColor = Color.White;
                    label2.Refresh();
                    break;
                case 2:
                    label3.BackColor = Color.Green;
                    System.Threading.Thread.Sleep(200);
                    label3.ForeColor = Color.White;
                    label3.Refresh();
                    break;
            }
        }

        private void Form4_Load(object sender, EventArgs e)
        {
            this.ClientSize = new Size(this.ClientSize.Width, label1.Height);
            Application.DoEvents();
            //
        }

        private void Form4_VisibleChanged(object sender, EventArgs e)
        {
            if (this.Visible)
            {
                AnimateWindow(this.Handle, 200, (int)(AnimateWindowFlags.AW_BLEND | AnimateWindowFlags.AW_HIDE));
            }
            else
            {
                AnimateWindow(this.Handle, 200, (int)(AnimateWindowFlags.AW_BLEND | AnimateWindowFlags.AW_ACTIVATE));
            }
            Application.DoEvents();
            //
        }
        //
    }
}
